package com.liu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liu.dao.ServeBeautyDao;
import com.liu.dto.ServeBeautyDto;
import com.liu.entity.ServeBeauty;
import com.liu.entity.ServeMedical;
import com.liu.service.intf.ServeBeautyService;
import com.liu.vo.PageBeanJson;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServeBeautyServiceImpl implements ServeBeautyService {
    @Autowired
    private ServeBeautyDao serveBeautyDao;

    @Override
    public PageBeanJson<ServeBeauty> list(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        PageInfo<ServeBeauty> pageInfo = new PageInfo<>(serveBeautyDao.select());
        System.out.println("美容:"+serveBeautyDao.select());
        System.out.println(pageInfo.getList());
        return new PageBeanJson<>(0, "ok", pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public R delete(int id) {
        int delete = serveBeautyDao.delete(id);
        return new R(delete, delete == 1 ? "ok" : "false", null);
    }

    @Override
    public R deleteBatch(int[] ids) {
        int delBatch = serveBeautyDao.delBatch(ids);
        return new R(delBatch, delBatch >= 1 ? "ok" : "false", null);
    }

    @Override
    public R insert(ServeBeauty serveBeauty) {
        int insert = serveBeautyDao.insert(serveBeauty);
        return new R(insert, insert == 1 ? "ok" : "false", null);
    }

    @Override
    public R update(ServeBeauty serveBeauty) {
        int update = serveBeautyDao.update(serveBeauty);
        return new R(update,update == 1 ? "ok" : "false", null);
    }

    @Override
    public PageBeanJson<ServeBeauty> search(ServeBeauty serveBeauty,int page,int pageSize) {
        List<ServeBeauty> search = serveBeautyDao.search(serveBeauty);
        PageHelper.startPage(page,pageSize);
        PageInfo<ServeBeauty> pageInfo = new PageInfo<>(search);
        return new PageBeanJson<>(0,"ok",pageInfo.getTotal(),pageInfo.getList());
    }
}
